<template>
    <div>
        <el-row style="margin-top: 50px">
            <el-col :span="12"><div>
                <el-input v-model="true_name" placeholder="请输入医生名称" style="width: 300px"></el-input>
                <el-button type="primary" @click="List">检索</el-button>
            </div></el-col>
            <el-col :span="12" >
                <div style="margin-left: 550px">
                    <el-button type="danger" @click="showDoctors">已禁用人数{{count}}</el-button>
                    <el-button type="primary" @click="addDcotor">添加医生</el-button>
            </div></el-col>
        </el-row>
        <el-row>
            <el-col :span="24"><div>
                <el-table
                        :data="doctorData"
                        border
                        style="width: 100%;text-align: center">
                    <el-table-column
                            fixed
                            prop="id"
                            label="序号">
                    </el-table-column>
                    <el-table-column
                            prop="true_name"
                            label="姓名">
                        <template slot-scope="scope">
                            {{scope.row.trueName}}
                        </template>
                    </el-table-column>
                    <el-table-column
                            prop="sex"
                            label="性别">
                        <template slot-scope="scope">
                            {{scope.row.sex==0?'男':'女'}}
                        </template>
                    </el-table-column>
                    <el-table-column
                            prop="age"
                            label="年龄">
                    </el-table-column>
                    <el-table-column
                            prop="phone"
                            label="电话">
                    </el-table-column>
                    <el-table-column
                            prop="department_name"
                            label="科室">
                        <template slot-scope="scope">
                            {{scope.row.hisMemberEntities.hisDepartmentEntities.departmentName}}
                        </template>
                    </el-table-column>
                    <el-table-column
                            prop="type"
                            label="职务">
                        <template slot-scope="scope">
                            {{scope.row.hisMemberEntities.type}}
                        </template>
                    </el-table-column>
                    <el-table-column
                            prop="create_time"
                            label="加入时间">
                        <template slot-scope="scope">
                            {{scope.row.hisMemberEntities.createTime}}
                        </template>
                    </el-table-column>
                    <el-table-column
                            fixed="right"
                            label="操作">
                        <template slot-scope="scope">
                            <el-button @click="handleClick(scope.row)" type="text" size="small">禁用</el-button>
                            <el-button type="text" size="small" @click="upClick(scope.row)">编辑</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                </div></el-col>
        </el-row>
        <div>
            <el-dialog
                    :visible.sync="dialogVisible">
                <el-table
                        :data="doctorDatas"
                        border
                        style="width: 100%;text-align: center" >
                    <el-table-column
                            fixed
                            prop="id"
                            label="序号">
                    </el-table-column>
                    <el-table-column
                            prop="trueName"
                            label="姓名">
                    </el-table-column>
                    <el-table-column
                            prop="sex"
                            label="性别">
                    </el-table-column>
                    <el-table-column
                            prop="age"
                            label="年龄">
                    </el-table-column>
                    <el-table-column
                            prop="phone"
                            label="电话">
                    </el-table-column>
                    <el-table-column
                            fixed="right"
                            label="操作">
                        <template slot-scope="scope">
                            <el-button @click="startBtn(scope.row)" type="text" size="small">启用</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-dialog>
        </div>
        <div>
            <el-dialog
                    :visible.sync="status2" width="600px">
                <doctorcu v-on:close="closes"></doctorcu>
            </el-dialog>
        </div>
        <div>
            <el-dialog
                    :visible.sync="status3" width="600px">

                <doctorcu v-if="status3" :upstatus="upstatus"></doctorcu>
            </el-dialog>
        </div>
    </div>
</template>

<script>
    import  DoctorManage from  '../../model/ww/DoctorManage'
    const  doctormanage=DoctorManage.getInstance();
    import DoctorCU from './DoctorCU'

    export default {
        name: "DoctorManage",
        methods: {
            List(){

              doctormanage.list(this.true_name).then((response)=>{
                      this.doctorData=response.data.data//给予表格赋值
                  if(this.doctorData==null){
                      return;
                  }
                this.doctorData.forEach(i=>{
                    let a=i.hisMemberEntities.type
                    if(a==1){
                        a='管理员'
                    }else if(a==2){
                        a='医生'
                    }else if(a==3){
                        a='护士'
                    }else if(a==4){
                        a='挂号员'
                    }else if(a==5){
                        a='收费员'
                    }else if(a==6){
                        a='发药员'
                    }else if(a==7){
                        a='财务'
                    }else if(a==8){
                        a='主管护师'
                    }else if(a==9){
                        a='主治医师'
                    }else if(a==10){
                        a='主任医师'
                    }else if(a==11){
                        a='实习医师'
                    }else if(a==12){
                        a='护师'
                    }else if(a==13){
                        a='研究生'
                    }else{
                        a='其他人员'
                    }
                    i.hisMemberEntities.type=a;
                })

              })
            },
            handleClick(row) {//点击禁用
                doctormanage.del(row.id).then(()=>{
                    this.count++;
                    this.List()
                    this.$message("禁用成功")
                })
            },
            showCountBtn(){//查看被禁用的个人数
                doctormanage.getDoctorCount().then((response)=>{
                           this.count=response.data.data
                })
            },
            showDoctors(){//查看被禁用的医生
                this.dialogVisible=!this.dialogVisible
               doctormanage.showDoctors().then((response)=>{
                   this.doctorDatas=response.data.data;
               })
            },
            startBtn(row){//启用被禁用的医生
                doctormanage.update(row.id).then(()=>{
                    this.List()
                    this.dialogVisible=!this.dialogVisible
                    this.showCountBtn()
                    this.$message("启用成功")
                })
            },
            addDcotor(){//添加医生
                 this.status2=!this.status2
            },
            closes(){
                this.List()
                this.showCountBtn()
                this.status2=!this.status2
            },
            upClick(row){ //编辑医生
                this.upstatus=row.id
                this.status3=!this.status3
            }
        },
        data() {
            return {
                doctorData:[], //医生信息的数据
                true_name:'',  //检索姓名
                count:0,  //禁用人数
                doctorID:[], //禁用的医生ID存在这里面方便后面查看或启用
                doctorDatas:[], //禁用的医生信息
                dialogVisible: false, //对话框状态
                status2:false, //添加医生对话框状态
                upstatus:0,   //判断是添加还是修改
                status3:false  //修改医生对话框状态
             }
        },
        created() {
            this.List()
            this.showCountBtn()

        },
        components:{
            doctorcu:DoctorCU
        }

    }
</script>

<style scoped>

</style>